<%@page import="org.springframework.context.annotation.Bean"%>
<%@page import="cn.egame.common.util.Utils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="cn.egame.interfaces.gc.TerminalInfo"%>
<%@page import="java.util.*"%>
<%@page import="cn.egame.interfaces.pu.AppParameter"%>
<%@page import="com.egame.manage.biz.utils.ConstVar"%>
<%@page import="cn.egame.interfaces.EnumType.AppParameterType"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/main.css"  />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
<title>新增机型</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
	function isTerminalExist(uacode){
		$.ajax({			
			url : "<%=request.getContextPath() + "/tv/terminal/exist.do" %>",
			type : 'post',
			data : {
				'uacode' : uacode
			},
			success : function(msg) {	
				if(msg==1)return true;
				else return false;
			}
		});
	}
	function formSubmit(){
		isTerminalExist(document.getElementById("UACode").value);
		var td = $("#form1").find("td[name='notnone']");
		var isSubmit = true;
		for(var i = 0; i<td.length; i++){
			if($(td[i]).find("input").val() == ""){
				$(td[i]).find("span").remove();
				$(td[i]).append("<span class='page_tip'>*必填</span>");
				isSubmit = false;
				return;
			}else{
				$(td[i]).find("span").remove();
			}
		}
		if($("#manufacturerId").val()==-1){
			alert("请选择品牌");
			isSubmit = false;
			return;
		}
		if($("#shortUA").val()==""){
			alert("请填写型号");
			return;
		}
		if($("#screenPx").val()==-1){
			alert("请选择分辨率");
			isSubmit = false;
			return;
		}
		
		if(isSubmit){
			document.getElementById("form1").submit();
		}else{
			return;
		}
	}

	function getOptionText(selectName){
		var select = document.getElementById(selectName);
		if(select == null)return null;
		var options = select.options;
		if(options == null)return null;
		var optionIndex = select.selectedIndex;
		if(optionIndex == null)return null;
		return options[optionIndex].text;
	}
	
	function getUA(){
		setTerminalName();
		terminalName = document.getElementById("terminalName").value;
		var shortUA = document.getElementById("shortUA").value;
		var screenPx = document.getElementById("screenPx").value;
		var UACode = document.getElementById("UACode");
		if($("#manufacturerId").val()==-1){
			alert("请选择品牌");
			return;
		}
		if($("#shortUA").val()==""){
			alert("请填写型号");
			return;
		}
		if($("#screenPx").val()==-1){
			alert("请选择分辨率");
			return;
		}		
		UACode.value = terminalName + "-" + shortUA + "-" + screenPx;
	}	
	function setTerminalName(){
		var text = getOptionText("manufacturerId");
		document.getElementById("terminalName").value = text.split("-")[1];
	}
</script>
</head>
<body>
<div class="matter_box">
	<div class="mt10 pt10 clearfix">
	<% 
		String urlString = request.getContextPath() + "/tv/terminal/update.do"; 
	%>
	<form action="<%=urlString %>" method="post" id="form1">
		<table class="table2">
			<%
				TerminalInfo bean = new TerminalInfo();
				if (request.getAttribute("bean") != null) {
					bean = (TerminalInfo) request.getAttribute("bean");
				}
			%>
			<tr>
				<td align=right>品牌</td>
				<td name="notnone">
					<input type=hidden name=terminalId value=<%=bean.getTerminalId() %>>
					<input type=hidden name=terminalName id=terminalName value="<%=bean.getTerminalName() %>">
					<select name="manufacturerId" id=manufacturerId onchange="setTerminalName()">
						<option value="-1">请选择</option>						
				<%
					List<String[]> brandMap = new ArrayList<String[]>();
					if(request.getAttribute("brandList")!=null){
						brandMap = (List<String[]>)request.getAttribute("brandList");						
						for(String[] key:brandMap){
							if(key.length == 3){
				%>
							<option value="<%=key[0] %>" <% if(key[0].equals("" + bean.getManufacturerId())){ %>selected<% } %> ><%=key[1] %>-<%=key[2] %></option>
				<%
						}
					}
					}
				%>
					</select>
				</td>
			</tr>
			<tr>
				<td align=right>型号</td>
				<td name="notnone"><input type=text name=shortUA id=shortUA value=<%=bean.getShortUA() %>>
				</td>
			</tr>
			<tr>
				<td align=right>分辨率</td>
				<td name="notnone">
					<select name=screenPx id=screenPx>
						<option value="-1" selected>请选择</option>
			<%
				List<AppParameter> pxList = new ArrayList<AppParameter>();
				if(request.getAttribute("pxList")!=null){
					pxList = (List<AppParameter>)request.getAttribute("pxList");
					for(AppParameter appBean:pxList){
						%>
						<option value="<%=appBean.getName() %>" <% if(appBean.getName().equals(bean.getScreenPx())){ %>selected<% } %>><%=appBean.getName() %></option>
						<%
					}
				}
			%>
					</select>
					<a class="btn2" href="javascript:setDialog('addScreenPx')">新建分辨率</a>
				</td>
			</tr>
			<tr>
				<td align=right>操作系统</td>
				<td>
				<select name=osName id=osName>
						<option value="">请选择</option>
			<%
				List<AppParameter> osList = new ArrayList<AppParameter>();
				if(request.getAttribute("osList")!=null){
					osList = (List<AppParameter>)request.getAttribute("osList");
					for(AppParameter appBean:osList){
						%>
						<option value="<%=appBean.getName() %>" <% if(appBean.getName().equals(bean.getOsName())){ %>selected<%} %>><%=appBean.getName() %></option>
						<%
					}
				}
			%>
					</select>
					<a class="os_btn" href="javascript:setDialog('addOS')">新建操作系统</a>
				</td>
			</tr>
			<tr>
				<td align=right>操作系统版本</td>
				<td><input type=text name=osVersion value=<%=bean.getOsVersion() %>></td>
			</tr>
			<tr>
				<td align=right>客户端UA特征串</td>
				<td name="notnone">
					<input type=text name=UACode id=UACode value=<%=bean.getUACode() %>>
					<input type=button class="btn3" value="获取特征串" onclick="getUA()">
				</td>
			</tr>
			<tr>
				<td align=right>芯片</td>
				<td><input type=text name=chipCode value=<%=bean.getChipCode() %>></td>
			</tr>
			<tr>
				<td align=right>是否支持触摸屏</td>
				<td>
					<input type="radio" name=isTouch value="1" <% if(bean.getIsTouch()==1){ %>checked<%} %>>是
					<input type="radio" name=isTouch value="0" <% if(bean.getIsTouch()==0){ %>checked<%} %>>否
				</td>
			</tr>
			<tr>
				<td align=right>机型备注</td>
				<td>					
					<input type=text name=remark value=<%=bean.getRemark() %>>
				</td>
			</tr>
			<tr><td align=center  colspan="2"><input type="button" value="提交" class="btn3" onclick="formSubmit()"></td></tr>
		</table>
	</form>
	</div>
	<div class="dialog_table editor_group" id="addScreenPx" style="width:400px">
	<h2 class="tc">新增分辨率</h2>
	<form action="<%=request.getContextPath() + "/tv/parameter/add.do"%>" method="post" id="addform">
		<table>
			<tr>
				<td align="right">分辨率:</td>
				<td class="pl25"  name="notnone">
					<input type=hidden name=parentId value=<%=ConstVar.APP_SCREEN_PX %> >
					<input type=hidden name=typeNum value=<%=AppParameterType.screenpx.value() %> >
					<input type=hidden name=depth value=2 >
					<input type=text name=name>
				</td>
			</tr>
			<tr>
				<td colspan=2 align="center">
					<input class="btn3" type="submit" value="提交">
				</td>			
			</tr>
		</table>
	</form>
	</div>
	<div class="dialog_table editor_group" id="addOS" style="width:400px">
	<h2 class="tc">新增操作系统</h2>
	<form action="<%=request.getContextPath() + "/tv/parameter/add.do"%>" method="post" id="addform">
		<table>
			<tr>
				<td align="right">操作系统:</td>
				<td class="pl25"  name="notnone">
					<input type=hidden name=parentId value=<%=ConstVar.APP_OS %> >
					<input type=hidden name=typeNum value=<%=AppParameterType.os.value() %> >
					<input type=hidden name=depth value=2 >
					<input type=text name=name>
				</td>
			</tr>
			<tr>
				<td colspan=2 align="center">
					<input class="btn3" type="submit" value="提交">
				</td>			
			</tr>
		</table>
	</form>
	</div>
</div>
</body>
</html>